package com.niuwa.p2p.service.impl.studentcust;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.niuwa.p2p.core.constant.StudentCustConstant;
import com.niuwa.p2p.core.mvc.entity.PageBean;
import com.niuwa.p2p.core.utils.DictUtil;
import com.niuwa.p2p.core.utils.StringUtil;
import com.niuwa.p2p.dao.customer.StudentCustDao;
import com.niuwa.p2p.entity.PageQuery;
import com.niuwa.p2p.entity.customer.StudentInfoFromApp;
import com.niuwa.p2p.service.studentcust.IStudentCustService;
@Service
public class StudentCustServiceImpl implements IStudentCustService {
	@Autowired
	private StudentCustDao studentCustDao;
	
	@Override
	public PageBean<StudentInfoFromApp> selectStudentList(Map<String, Object> paramsMap) {
		assert paramsMap.get(PageQuery.PAGEQUERY) != null;
		List<StudentInfoFromApp> studentlist = studentCustDao.selectStudentList(paramsMap);
		for(StudentInfoFromApp studentInfoFromApp:studentlist){
			String schoolCity = DictUtil.getDictNameByTypeAndCode("CITY_CODE",studentInfoFromApp.getCity());//;
			String province = DictUtil.getDictNameByTypeAndCode("PROVINCE_CODE",studentInfoFromApp.getProvince());
			schoolCity = StringUtil.isNullOrEmpty(schoolCity)?StudentCustConstant.NULL_CITY_DESC:schoolCity;
			province = StringUtil.isNullOrEmpty(province)?StudentCustConstant.NULL_PROVINCE_DESC:province;
			studentInfoFromApp.setArea(province+StudentCustConstant.CONNECT_SYMBOL+schoolCity);
		}
		int totalCount = studentCustDao.countStudents();
		PageBean<StudentInfoFromApp> page = new PageBean<StudentInfoFromApp>(totalCount);
		// 设置当前页
		page.setPage(((PageQuery) paramsMap.get(PageQuery.PAGEQUERY)).getPage());
		page.setRows(studentlist);
		return page;
	}
}
